package com.txts.road.app.vehicle.controller;

import com.txts.road.app.vehicle.model.dto.VehicleDTO;
import com.txts.road.app.vehicle.model.vo.VehicleVO;
import com.txts.road.app.vehicle.service.VehicleService;
import com.txts.base.common.domain.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;

import jakarta.validation.Valid;

import java.util.List;

/**
 * 版本更新前端控制层
 *
 * @author baoyr
 * @since 2025-07-17 10:48
 */
@Tag(name = "车辆信息")
@RestController
@RequestMapping("/api/v1/vehicle")
@RequiredArgsConstructor
public class VehicleController {
    private final VehicleService vehicleService;

    /**
     * 添加车辆
     */
    @Operation(summary = "添加车辆")
    @PostMapping("/add")
    public ResponseDTO<Boolean> addVehicle(@Valid @RequestBody VehicleDTO addDTO) {
        return ResponseDTO.ok(vehicleService.addVehicle(addDTO));
    }

    /**
     * 获取用户车辆列表
     */
    @Operation(summary = "获取用户车辆列表")
    @GetMapping("/list")
    public ResponseDTO<List<VehicleVO>> getVehicleList() {
        return ResponseDTO.ok(vehicleService.getVehicleList());
    }

    /**
     * 更新车辆信息
     */
    @Operation(summary = "更新车辆信息")
    @PutMapping("/update")
    public ResponseDTO<Boolean> updateVehicle(@Valid @RequestBody VehicleDTO updateDTO) {
        return ResponseDTO.ok(vehicleService.updateVehicle(updateDTO));
    }

    /**
     * 删除车辆
     */
    @Operation(summary = "删除车辆")
    @DeleteMapping("/{vehicleId}")
    public ResponseDTO<Boolean> deleteVehicle(@PathVariable Long vehicleId) {
        return ResponseDTO.ok(vehicleService.deleteVehicle(vehicleId));
    }

    /**
     * 设置默认车辆
     */
    @Operation(summary = "设置默认车辆")
    @PutMapping("/{vehicleId}/default")
    public ResponseDTO<Boolean> setDefaultVehicle(@PathVariable Long vehicleId) {
        return ResponseDTO.ok(vehicleService.setDefaultVehicle(vehicleId));
    }
}
